package com.wallet.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自定义消息队列配置
 * @author zhangguangyuang
 */
@Configuration
public class MyRabbitMQConfig {
    /* 容器中的Queue、Exchange、Binding 会自动创建（在RabbitMQ）不存在的情况下 */

    /**
     * 付款队列-普通队列
     * @return
     */
    @Bean
    public Queue paymentQueue(){
        Queue queue = new Queue("wallet.payment.wallet.queue",true,false,false);
        return queue;
    }

    /**
     * 付款交换机
     * TopicExchange
     * @return
     */
    @Bean
    public Exchange paymentEventExchange(){
        return new TopicExchange("payment-event-exchange",true,false);
    }
    /**
     * String destination, 目的地(队列名或者交换机名字)
     * DestinationType destinationType, 目的地类型(Queue、Exhcanage)
     * String exchange,
     * String routingKey,
     * Map<String, Object> arguments
     */
    @Bean
    public Binding paymentCreateBinding(){
        return new Binding("wallet.payment.wallet.queue",
                Binding.DestinationType.QUEUE,
                "payment-event-exchange",
                "pay.create.pay",
                null);
    }

    /**
     * 钱包退款队列-普通队列
     * @return
     */
    @Bean
    public Queue refundQueue(){
        Queue queue = new Queue("wallet.refund.wallet.queue",true,false,false);
        return queue;
    }

    /**
     * 退款交换机
     * TopicExchange
     * @return
     */
    @Bean
    public Exchange refundEventExchange(){
        return new TopicExchange("refund-event-exchange",true,false);
    }

    /**
     * 钱包退款队列与退款交换机绑定
     * @return
     */
    @Bean
    public Binding orderReleaseOtherBinding(){
        return new Binding("wallet.refund.wallet.queue",
                Binding.DestinationType.QUEUE,
                "refund-event-exchange",
                "refund.create.refund",
                null);
    }

}
